/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.kosongkosong.controller;

import com.kosongkosong.service.DataService;
import com.kosongkosong.wrapper.StoryIdListWrapper;
import com.kosongkosong.wrapper.StoryListWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author ifnu
 */
@Controller
public class NewsController {

    @Autowired private DataService dataService;

    @RequestMapping(value="/news/{start}/{num}",method=RequestMethod.GET)
    public ModelAndView news(@PathVariable("start") int start,
            @PathVariable("num") int num){
        ModelAndView view = new ModelAndView();
        StoryListWrapper wrapper = new StoryListWrapper();
        wrapper.setStories(dataService.getStories(start, num));
        view.addObject(wrapper);
        return view;
    }

    @RequestMapping(value="/news/id/{start}/{num}",method=RequestMethod.GET)
    public ModelAndView newsId(@PathVariable("start") int start,
            @PathVariable("num") int num){
        ModelAndView view = new ModelAndView();
        StoryIdListWrapper wrapper = new StoryIdListWrapper();
        wrapper.setStoryIds(dataService.getStoryIds(start, num));
        view.addObject(wrapper);
        return view;
    }


}
